#include <iostream>
#include <vector>
using namespace std;


int binary(const vector<int>& arr1,
           const vector<int>& arr2,
           int l1,
           int r1,
           int l2,
           int r2) {
    if (l1 == r1) return min(arr1[l1], arr2[l2]);
    int mid1 = (r1 + l1) / 2, mid2 = (r2 + l2) / 2;
    if (arr1[mid1] == arr2[mid2]) return arr1[mid1];
    if (arr1[mid1] < arr2[mid2]) return binary(arr2, arr1, l2, r2, l1, r1);
    if ((r1 - l1 + 1) % 2 == 1)
        return binary(arr1, arr2, l1, mid1, mid2, r2);
    else
        return binary(arr1, arr2, l1, mid1, mid2 + 1, r2);
}

int findMedianinTwoSortedAray(vector<int>& arr1, vector<int>& arr2) {
    return binary(arr1, arr2, 0, arr1.size() - 1, 0, arr2.size() - 1);
}